package com.ygqh.baby.service.wechat.notify;

import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.type.TradeType;
import com.foxinmy.weixin4j.util.RandomUtil;
import com.ygqh.baby.service.wechat.model.WxPayAccount;

/**
 * JS支付订单详情
 * 
 * @className YgMchPayPackage
 * @author guohao
 * @date 2017/01/13
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class YgMchPayPackage extends YgPayPackage {

	private static final long serialVersionUID = 8944928173669656177L;

	/**
	 * 微信分配的公众账号 必须
	 */
	@XmlElement(name = "appid")
	@JSONField(name = "appid")
	private String appId;
	/**
	 * 微信支付分配的商户号 必须
	 */
	@XmlElement(name = "mch_id")
	@JSONField(name = "mch_id")
	private String mchId;

	/**
	 * 微信分配的子商户公众账号ID 非必须
	 */
	@XmlElement(name = "sub_appid")
	@JSONField(name = "sub_appid")
	private String subAppId;
	/**
	 * 微信支付分配的子商户号 非必须
	 */
	@XmlElement(name = "sub_mch_id")
	@JSONField(name = "sub_mch_id")
	private String subMchId;
	/**
	 * 微信支付分配的终端设备号 非必须
	 */
	@XmlElement(name = "device_info")
	@JSONField(name = "device_info")
	private String deviceInfo;
	/**
	 * 随机字符串,不长于 32 位 必须
	 */
	@XmlElement(name = "nonce_str")
	@JSONField(name = "nonce_str")
	private String nonceStr;
	/**
	 * 签名 <font color="red">调用者无需关心</font>
	 */
	private String sign;
	/**
	 * 交易类型JSAPI、NATIVE、APP 必须
	 */
	@XmlElement(name = "trade_type")
	@JSONField(name = "trade_type")
	private String tradeType;
	/**
	 * 用户在商户 appid 下的唯一 标识, trade_type 为 JSAPI 时,此参数必传
	 */
	@XmlElement(name = "openid")
	@JSONField(name = "openid")
	private String openId;
	/**
	 * 只在 trade_type 为 NATIVE 且【模式一】 时需要填写 非必须
	 */
	@XmlElement(name = "product_id")
	@JSONField(name = "product_id")
	private String productId;
	/**
	 * 指定支付方式:no_credit--指定不能使用信用卡支付
	 */
	@XmlElement(name = "limit_pay")
	@JSONField(name = "limit_pay")
	private String limitPay;
	/**
	 * 服务商下的用户子标识 非必须
	 */
	@XmlElement(name = "sub_openid")
	@JSONField(name = "sub_openid")
	private String subOpenId;

	protected YgMchPayPackage() {
		// jaxb required
	}

	public YgMchPayPackage(WeixinPayAccount weixinAccount, String openId, String body, String outTradeNo, int totalFee, String notifyUrl, String createIp,
			TradeType tradeType) {
		this(weixinAccount, openId, body, outTradeNo, totalFee, notifyUrl, createIp, tradeType, null);
	}

	public YgMchPayPackage(WeixinPayAccount weixinAccount, String openId, String body, String outTradeNo, int totalFee, String notifyUrl, String createIp,
			TradeType tradeType, String attach) {
		this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount.getDeviceInfo(), body, outTradeNo, totalFee, notifyUrl, createIp, tradeType, openId,
				attach, null, null, null, null, null);
	}

	public YgMchPayPackage(String appId, String mchId, String deviceInfo, String body, String outTradeNo, int totalFee, String notifyUrl, String createIp,
			TradeType tradeType, String openId, String attach, Date timeStart, Date timeExpire, String goodsTag, String productId, String limitPay) {
		super(body, outTradeNo, totalFee, notifyUrl, createIp, attach, timeStart, timeExpire, goodsTag);
		this.appId = appId;
		this.mchId = mchId;
		this.deviceInfo = deviceInfo;
		this.nonceStr = RandomUtil.generateString(16);
		this.tradeType = tradeType.name();
		this.openId = openId;
		this.productId = productId;
		this.limitPay = limitPay;
	}

	public YgMchPayPackage(WxPayAccount weixinAccount, String openId, String subOpenId, String body, String outTradeNo, int totalFee, String notifyUrl,
			String createIp, TradeType tradeType, String attach) {
		this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount.getSubId(), weixinAccount.getSubMchId(), body, outTradeNo, totalFee, notifyUrl,
				createIp, tradeType.name(), openId, subOpenId, RandomUtil.generateString(16), attach, null, null, null, null);

	}

	public YgMchPayPackage(String appId, String mchId, String subAppId, String subMchId, String body, String outTradeNo, int totalFee, String notifyUrl,
			String createIp, String tradeType, String openId, String subOpenId, String nonceStr, String attach, String deviceInfo, Date timeStart,
			Date timeExpire, String goodsTag) {
		super(body, outTradeNo, totalFee, notifyUrl, createIp, attach, timeStart, timeExpire, goodsTag);
		this.appId = appId;
		this.mchId = mchId;
		this.subAppId = subAppId;
		this.subMchId = subMchId;
		this.deviceInfo = deviceInfo;
		this.nonceStr = nonceStr;
		this.tradeType = tradeType;
		this.openId = openId;
		this.subOpenId = subOpenId;
	}

	public String getSubAppId() {
		return subAppId;
	}

	public void setSubAppId(String subAppId) {
		this.subAppId = subAppId;
	}

	public String getSubMchId() {
		return subMchId;
	}

	public void setSubMchId(String subMchId) {
		this.subMchId = subMchId;
	}

	public String getSubOpenId() {
		return subOpenId;
	}

	public void setSubOpenId(String subOpenId) {
		this.subOpenId = subOpenId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	public void setMchId(String mchId) {
		this.mchId = mchId;
	}

	public void setDeviceInfo(String deviceInfo) {
		this.deviceInfo = deviceInfo;
	}

	public void setNonceStr(String nonceStr) {
		this.nonceStr = nonceStr;
	}

	public void setTradeType(String tradeType) {
		this.tradeType = tradeType;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public String getAppId() {
		return appId;
	}

	public String getMchId() {
		return mchId;
	}

	public String getDeviceInfo() {
		return deviceInfo;
	}

	public String getNonceStr() {
		return nonceStr;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getTradeType() {
		return tradeType;
	}

	public String getOpenId() {
		return openId;
	}

	public String getProductId() {
		return productId;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public String getLimitPay() {
		return limitPay;
	}

	public void setLimitPay(String limitPay) {
		this.limitPay = limitPay;
	}

	@Override
	public String toString() {
		return "YgMchPayPackage [appId=" + appId + ", mchId=" + mchId + ", subAppId=" + subAppId + ", subMchId=" + subMchId + ", deviceInfo=" + deviceInfo
				+ ", nonceStr=" + nonceStr + ", sign=" + sign + ", tradeType=" + tradeType + ", openId=" + openId + ", productId=" + productId + ", limitPay="
				+ limitPay + ", subOpenId=" + subOpenId + "]";
	}

}
